package com.blog.dao.admincategory;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.blog.dao.conn.BaseDao;
import com.blog.dao.conn.ParamSet;
import com.blog.dao.conn.RowDatas;
import com.blog.entity.ArticleEntity;
import com.blog.entity.TypesEntity;

public class AdminCategoryDao extends BaseDao{

	private RowDatas<TypesEntity> types = new RowDatas<TypesEntity>() {

		@Override
		public TypesEntity getRowData(ResultSet rs) throws SQLException {
			TypesEntity te = new TypesEntity();
			te.setTypes_id(rs.getInt("types_id"));
			te.setTypes_name(rs.getString("types_name"));
			te.setTypes_url(rs.getString("types_url"));
			te.setArticle_typesid(rs.getInt("name"));
			return te;
		}
	};
	/**
	 * 查看所有分类
	 */
	public List<TypesEntity> queryAllTypes() {
		String sql = "select COUNT(types_id) name,t.types_id,t.types_name,t.types_url from tb_types t \r\n" + 
				"LEFT JOIN tb_article a ON t.types_id = a.article_typesid\r\n" + 
				" GROUP BY(t.types_id)";
		System.out.println(sql);
		return queryList(sql, types);
	}
	
	/**
	 * 修改分类
	 */
	public int updateTyeps(String name , int num) {
		int row = 0;
		String sql = "update tb_types set types_name =? where types_id = ?";
		row = updateExecuted(sql,new ParamSet(name,num));
		return row;
		
	}
}
